<?php


namespace app\home\controller;

use think\Db;
use think\facade\Config;
use app\common\library\Qiniu;

class Index extends Base
{

    protected $beforeActionList = [
        'first',
    ];

    protected function first()
    {

        $this->assign('nav', 'index');
    }

    public function index()
    {
        $slide = DB::name('slide')->where('slide_type', 1)->page(1, 6)->order('c_time desc')->cache(360)->select();
        $qiniu = new Qiniu;
        foreach ($slide as &$item) {
            $item['file_path'] = str_replace("/qiniu/downloadurl?file=", "", $item['file_path']);
            $item['file_path'] = $qiniu->getimgurl($item['file_path']);
        }

        $this->assign('slide', $slide);
        $slide = DB::name('product')->page(1, 6)->order('c_time desc')->cache(360)->select();
        foreach ($slide as &$item) {
            $item['file_path'] = str_replace("/qiniu/downloadurl?file=", "", $item['file_path']);
            $item['file_path'] = $qiniu->getimgurl($item['file_path']);
        }
        $this->assign('product', $slide);
        //首页宣传
        $ad = Db::name('news')
            ->where('category_id', 5)
            // ->fetchSql(true)
            ->order('id desc')->page(input("page"), 20)->cache(360)->select();
        //dump($ad);
        $this->assign('news', $ad);


        return view();
    }

    public function about()
    {
        return view();
    }

    public function product()
    {

        $slide = DB::name('product')->order('c_time desc')->cache(360)->select();
        $this->assign('product', $slide);
        $slide = DB::name('product')->order('c_time desc')->cache(360)->page(1, 2)->select();
        $this->assign('product_ad', $slide);
        return view();
    }

    public function details()
    {
        return view();
    }

    public function service()
    {
        return view();
    }
}